package com.butterfly.vv;

import com.beem.project.beem.R;
import com.beem.project.beem.ui.ContactList;
import com.butterfly.vv.vv.utils.Debug;

import android.app.Activity;
import android.content.Intent;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;

public class VcardUI extends Activity {
	
	Spinner spinner;
	 ArrayAdapter<String> adapter01;
	 ArrayAdapter<String> adapter02;
	 private String[] arrayOfString = {"1","2","3"};
	 private String[][] arrayOfString1 = {{"11","12"},{"21","22"},{"31","32"}};
	 private Spinner prov_spr;
	 private Spinner city_spr;
	 Button next;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.vcard);
		spinner = (Spinner) findViewById(R.id.spinnerUniv);
		// spinner.setAdapter(new SpinnerAdapter)
		adapter01 = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, arrayOfString);
		adapter01
				.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
		prov_spr = (Spinner) this.findViewById(R.id.spiner01);
		prov_spr.setAdapter(adapter01);
		prov_spr.setOnItemSelectedListener(selectListener);
		city_spr = (Spinner) this.findViewById(R.id.spiner02);
		city_spr.setAdapter(adapter02);
		city_spr.setOnItemSelectedListener(selectListener01);
		next = (Button) findViewById(R.id.next);
		next.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startActivity(new Intent(VcardUI.this, ContactList.class));
				Debug.getDebugInstance().log("re "+prov_spr.getSelectedItem().toString()+"  "+city_spr.getSelectedItem().toString());
				finish();
			}
		});
	}
	
	private OnItemSelectedListener selectListener = new OnItemSelectedListener(){

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			int pos = prov_spr.getSelectedItemPosition();
			   adapter02 = new ArrayAdapter<String>(VcardUI.this,
			   android.R.layout.simple_spinner_item, arrayOfString1[pos]);
			   city_spr.setAdapter(adapter02);
			   next.setEnabled(true);
			   Debug.getDebugInstance().log("--"+city_spr.getSelectedItem().toString());
		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub
			
		}
		
	};
	
	private OnItemSelectedListener selectListener01= new OnItemSelectedListener() {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			Debug.getDebugInstance().log("-->"+city_spr.getSelectedItem().toString());
		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub
			
		}
		
	};
	
}
